<template>
  <div class="policydetails">
    <img v-if="imgflag==1" @touchstart="start" @touchend="end" class="imggg"  :src="img" alt="">
    <img v-else class="imggg" :src="img" alt="">
  </div>
</template>
<script lang="ts">
import '../../style/reservaIndex_index.css';
import 'vant/lib/toast/style';
import 'vant/lib/dialog/style';
import { Component, Vue, Prop } from 'vue-property-decorator';
import { cloudApi } from '@/api/indexApi';
import Header from '@/components/Header.vue';
import { Dialog  } from 'vant';
import { Toast } from 'vant';
import {  Alert } from '@/utils';
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
Vue.use(Dialog);
Component.registerHooks(['beforeRouteUpdate', 'beforeRouteLeave', 'beforeRouteLeave']);
@Component({
  components: { Header },
})
export default  class PolicyDetails extends Vue{
  img:any=''
  imgflag:any=''
  ftype:any=''
  fname:any=''
  loop:any=''
    create(){
    }
    mounted() {
     Dialog.alert({ title: '温馨提示', message: '请您长按图片保存到本地相册',confirmButtonText: "我知道了"});
     this.imgflag=localStorage.getItem('isappflag')

     this.img=localStorage.getItem('pilicyimg')
     this.ftype="."+this.img.split("https://wechat.chinalife-p.com.cn")[1].split(".")[1]
     this.fname=this.img.split("send/images/")[1].split(".")[0]
    }
    downnimg(){
      var obj = {
        "comFlag": "GSW",
        "fileUrl": this.img,
        "fileType": this.ftype,
        "fileName": this.fname,
        "fileId": "WAAAo91qe0w4774",
        "callback": "downloadFileCustomizeCallback"
      };
       this.downLoadimgFile(obj);
        window.downloadFileCustomizeCallback = downloadFileCustomizeCallback;
        function downloadFileCustomizeCallback(res) {
            console.log("基座反参：" + JSON.stringify(res))
            if (res.isSuccess === 'Y') {
                if (navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Linux') > -1) {
                   Toast('保存成功');
                } else {
                    Toast('保存成功');
                }

            } else {
                Toast('保存失败');
            }
        }
    }
    start () {

      clearTimeout(this.loop); //再次清空定时器，防止重复注册定时器

      this.loop = setTimeout(() => {
      Dialog.confirm({ title: '温馨提示',message: '保存到本地相册',}) .then(() => { this.downnimg() }).catch(() => {});
      }, 1000);

    }
    end () {

      clearTimeout(this.loop); //清空定时器，防止重复注册定时器

    }
    downLoadimgFile(obj: any) {
        const u = navigator.userAgent;
        const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; // android终端
        const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
        if (isAndroid) {
           window. SysClientJs. downloadFileCustomize (JSON.stringify(obj));
        } else {
           window.webkit.messageHandlers.downloadFileCustomize.postMessage(JSON.stringify(obj))
        }
    };
}
</script>
<style lang="less" scoped>
* { touch-action: pan-y; }
.imggg{
    width:100%;
}
#app{
  background: white;
}
.van-button__text{
  color: #1B8F5A;
}
</style>
